package com.example.callcenter.rabbitmq;

import com.example.callcenter.config.RabbitMQConfig;
import com.example.callcenter.dto.SmsDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SmsProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendSms(SmsDTO smsDTO) {
        log.info("消息sms生产者开始发送短信消息: {}", smsDTO); // 添加此行
        rabbitTemplate.convertAndSend(
                RabbitMQConfig.SMS_EXCHANGE,
                RabbitMQConfig.SMS_ROUTING_KEY,
                smsDTO,
                msg -> {
                    msg.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
                    return msg;
                }
        );
        log.info("消息sms生产者短信消息发送完成"); // 添加此行
    }
}